package com.fessc.develop.config;

import org.springframework.boot.SpringBootVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.HashSet;
import java.util.Set;

@EnableOpenApi
@Configuration
public class SwaggerConfig {

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API Document")
                .description("接口文档")
                .version(SpringBootVersion.getVersion())
                .build();
    }

    @Bean
    public Docket createRestApi() {
        Set<String> protocalSet = new HashSet<>();
        protocalSet.add("http");
        protocalSet.add("https");
        return new Docket(DocumentationType.OAS_30)
                .pathMapping("/")
                .enable(true)
                .apiInfo(apiInfo())
                .host("http://localhost:8080")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.fessc.develop.demos.web"))
                .paths(PathSelectors.any())
                .build()
                .protocols(protocalSet);
    }
}
